package com.gmstu.springframework.aop.aspect;

import com.gmstu.springframework.aop.intercept.GpMethodInterceptor;
import com.gmstu.springframework.aop.intercept.GpMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author John.zhang
 * @version Id: GpMethodThrowingAdviceInterceptor, v 1.0 2020/8/26 17:39 ZhiYong Exp $
 */
public class GpMethodThrowingAdviceInterceptor extends GpAbstractAspectAdvice implements GpMethodInterceptor {

    private String throwingName;

    public GpMethodThrowingAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(GpMethodInvocation invocation) throws Throwable {
        try {
            return invocation.proceed();
        } catch (Throwable throwable) {
            invokeAdviceMethod(invocation, null, throwable.getCause());
            throw throwable;
        }
    }

    public void setThrowingName(String throwingName) {
        this.throwingName = throwingName;
    }
}
